package com.woniu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.config.MinIOConfig;
import com.woniu.dto.DepartmentQueryDTO;
import com.woniu.entity.Department;
import com.woniu.service.DepartmentService;
import com.woniu.util.MinIOUtils;
import com.woniu.util.PageData;
import com.woniu.util.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@AllArgsConstructor
@RequestMapping("/systemManage")
public class SystemController {
    @Resource
    private DepartmentService departmentService;
    //private MinIOConfig minIOConfig;

/**
     * @Description
     对部门信息模糊查询
     * @Return
     * @Author  Ben
     * @Date  Create by 2025/2/17
     */
    @RequestMapping("/queryDepartment")
    public ResponseData<?> queryDepartment(@RequestBody PageData<DepartmentQueryDTO> pageData) {
        return departmentService.queryDepartment(pageData);
    }
    //增加部门
    @RequestMapping("/addDepartment")
    public ResponseData<?> addDepartment(@RequestBody Department department) {
        return departmentService.addDepartment(department);
    }
    //查询所有部门
    @RequestMapping("/queryAllDepartment")
    public ResponseData<?> queryAllDepartment() {
        return departmentService.queryAllDepartment();
    }
    //批量更新部门
    @RequestMapping("/updateDepartment")
    public ResponseData<?> updateDepartment(@RequestBody List<Department> departments) {
        return departmentService.batchUpdateDepartment(departments);
    }
    //删除部门
    @RequestMapping("/batchDeleteDepartment")
    public ResponseData<?> batchDeleteDepartment(@RequestBody List<Long> ids) {
        return departmentService.batchDeleteDepartment(ids);
    }
    //导出部门详情excel
    @RequestMapping("/outDepartmentExcel")
    public ResponseData<?> outDepartmentExcel(@RequestBody HttpServletResponse response,@RequestBody List<Long> ids) throws IOException {
        return departmentService.outDepartmentExcel(response, ids);
    }
    //初始化导入模板并上传
    @GetMapping("/outDepartmentExcelTemplate")
    public ResponseData<?> outDepartmentExcelTemplate(@RequestBody HttpServletResponse response) throws IOException {
        return departmentService.outDepartmentExcelTemplate(response);
    }

    @PostMapping("/importDepartmentExcel")
    public ResponseData<?> importDepartmentExcel(@RequestBody MultipartFile file) throws Exception {

        return departmentService.importDepartmentExcel(file);
    }

}
